package org.microframework.base.feign.logs;

import org.microframework.base.core.constant.ServiceNameConstants;
import org.microframework.base.feign.logs.factory.RemoteLogFallbackFactory;
import org.microframework.base.model.logs.domain.OperationLog;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 日志服务
 */
@FeignClient(contextId = "remoteLogService", value = ServiceNameConstants.LOGS_SERVICE, fallbackFactory = RemoteLogFallbackFactory.class)
public interface RemoteLogService {
	
	/**
	 * 记录登录失败日志
	 * 
	 * @param username 用户名
	 * @param errorMessage 错误消息
	 * @param ip 客户端IP
	 * @param location 地理位置
	 * @param browser 浏览器
	 * @param os 操作系统
	 */
	@PostMapping("/log/login/failure")
	void recordLoginFailure(@RequestParam("username") String username, 
	                         @RequestParam("errorMessage") String errorMessage,
	                         @RequestParam("ip") String ip,
	                         @RequestParam(value = "location", required = false) String location,
	                         @RequestParam(value = "browser", required = false) String browser,
	                         @RequestParam(value = "os", required = false) String os);
	
	/**
	 * 记录登录成功日志
	 * 
	 * @param username 用户名
	 * @param ip 客户端IP
	 * @param location 地理位置
	 * @param browser 浏览器
	 * @param os 操作系统
	 */
	@PostMapping("/log/login/success")
	void recordLoginSuccess(@RequestParam("username") String username,
	                        @RequestParam("ip") String ip,
	                        @RequestParam(value = "location", required = false) String location,
	                        @RequestParam(value = "browser", required = false) String browser,
	                        @RequestParam(value = "os", required = false) String os);

	/**
	 * 保存操作日志
	 * 
	 * @param operLog 操作日志对象
	 * @param inner 是否内部调用
	 */
	@PostMapping("/log/save")
	void saveLog(@RequestBody OperationLog operLog, @RequestParam("inner") String inner);
}
